package com.breaker.kata.algorithm;

public class Code02_RandToRand {

    public static void main(String[] args) {
        System.out.println("测试开始");
        int testTimes = 10000000;
        int count = 0;
        for (int i = 0; i < testTimes; i++) {
            if (Math.random() < 0.7) {
                count++;
            }
        }
        System.out.println((double) count / (double) testTimes);
    }

    public static double xToxPower2() {
        return Math.max(Math.random(), Math.random());
    }

    public static int randomNumGenerator() {
        return (int) (Math.random() * 5) + 1;
    }

    public static int f2() {
        int ans = 0;
        do {
            ans = randomNumGenerator();
        } while (ans == 3);
        return ans < 3 ? 0 : 1;
    }

    //等概率返回0～7 等概率返回
    public static int f3() {
        return (f2() << 2) + (f2() << 1) + f2();
    }

    //等概率返回1～6 等概率返回
    public static int g() {
        int ans;
        do {
            ans = f3();
        } while (ans == 0);
        return ans;
    }

    //你只能知道，x会以固定概率返回0和1，但是x的内容，你看不到！
    public static int x() {
        return Math.random() < 0.84 ? 0 : 1;
    }

    //等概率的返回0 和1
    public static int y() {
        int ans;
        do {
            ans = x();
        } while (ans == x());
        return ans;
    }
}
